home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / General tools / Report Error 2.0 / FailureHandler.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-17  |  2.3 KB  |  96 lines  |  [TEXT/KAHL]

  1. /*============================================================
  2.     FailureHander.h
  3.     
  4.     greggor@apple.com
  5. ============================================================*/
  6. #ifndef __FAILUREHANDLER__
  7. #define __FAILUREHANDLER__
  8.  
  9. #ifndef __RESOURCES__
  10. #include <Resources.h>
  11. #endif
  12.  
  13. #ifndef __MEMORY__
  14. #include <Memory.h>
  15. #endif
  16.  
  17. #include <setjmp.h>
  18.  
  19. #define ePointerNil            -110
  20. #define eGeneralErr            -1
  21. #define eAssertionFailure    -30000
  22.  
  23. #define kMagicFailID        'fail'
  24.  
  25. #define kInExceptionHandler    0x001
  26.  
  27. /*
  28. // Data types:
  29. */
  30. struct FailStack
  31. {
  32.     struct FailStack*        next;
  33.     OSErr                    error;
  34.     jmp_buf                    env;
  35.     long                    magicFailID;
  36.     long                    flags;
  37. };
  38.  
  39. typedef struct FailStack    FailStack;
  40.  
  41. typedef void (*NotifyFailureProc)(void);
  42.  
  43. /*
  44. // Globals:
  45. */
  46. extern FailStack*            gFailStack;
  47.  
  48. /*
  49. // Prototypes
  50. */
  51. void                        SetupTry(FailStack* failInfo);
  52. void                        PopFailureStack(void);
  53. void                        Failure( OSErr theErr );
  54. void                        FailOSErr( OSErr theErr );
  55. OSErr                        TheFailError(void);
  56. void                        FailAgain(void);
  57.  
  58. void                        SetExceptionNotifyProc(NotifyFailureProc notifyProc);
  59. Boolean                        ExceptionNotifyProcInstalled(void);
  60.  
  61. void                        MakeVariableNoRegister( void* foo );
  62.  
  63. /*
  64. //    TRY / EXCEPT / ENDTRY macros
  65. */
  66. #define TRY                    do { FailStack failInfo; SetupTry(&failInfo); if( setjmp(failInfo.env) == 0 )
  67. #define EXCEPT                else
  68. #define ENDTRY                PopFailureStack(); } while(false);
  69.  
  70. /*
  71. // This macro references the address of the specified local
  72. // variable; this will prevent the compiler from using the
  73. // variable as a register variable.
  74. */
  75. #define NOREGISTER(x)        ( MakeVariableNoRegister( (void*)(&(x)) ) )
  76.  
  77. /*
  78. //    Convenience macros
  79. */
  80. #define FailResError()                FailOSErr( ResError() )
  81. #define FailMemError()                FailOSErr( MemError() )
  82. #define FailThreadError()            FailOSErr( ThreadError() )
  83. #define FailNil( ptr )                if( ptr == nil ) FailOSErr( ePointerNil )
  84. #define Fail()                        FailOSErr( eGeneralErr )
  85. #define FailResErrorOrNil(ptr)        do { FailResError(); FailNil(ptr); } while(false)
  86. #define FailMemErrorOrNil(ptr)        do { FailMemError(); FailNil(ptr); } while(false)
  87.  
  88. /*
  89. // Assertion macros
  90. */
  91. #define Assert(truth)                if( !(truth) ) FailOSErr( eAssertionFailure )
  92. #define AssertPtrValid(p)            if( (p == nil) || (((long)(p) & 1) != 0) ) FailOSErr( eAssertionFailure )
  93. #define AssertHandleValid(h)        AssertPtrValid(h); AssertPtrValid(*h)
  94.  
  95. #endif
  96.